package org.jeecg.modules.flow.sys.mytest.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.flow.sys.mytest.entity.Goal;
import org.jeecg.modules.flow.sys.mytest.service.GoalService;
import org.jeecg.modules.system.service.impl.ThirdAppDingtalkServiceImpl;
import org.jeecg.modules.system.vo.thirdapp.SyncInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
 * 项目名称:    wms-server-jeecg
 * 接口描述:    流程操作信息
 * 创建人员:    zhaojun
 * 创建时间:    2023-09-14
 */
@Api(tags = "流程操作信息")
@RestController
@RequestMapping("/flow/info")
@Slf4j
public class MytestContorller {

    @Autowired
    private GoalService goalService;
    @Autowired
    private ThirdAppDingtalkServiceImpl dingtalkService;

    /**
     * 查询所有的流程
     *
     * @param businessType
     * @param documentType
     * @return
     */
    @ApiOperation(value = "查询所有的流程", notes = "查询所有的流程态")
    @GetMapping("/goalList")
    public Result<List<Goal>> goalList(String businessType, String documentType) {
        return Result.ok(goalService.list(businessType, documentType));
    }

    /**
     * 发送钉钉给用户
     *
     * @param message
     * @return
     */
    @ApiOperation(value = "发送钉钉给用户", notes = "发送钉钉给用户")
    @PostMapping("/sendMessage")
    public Result sendMessage(@RequestBody MessageDTO message) {
        boolean b = dingtalkService.sendMessage(message);
        return Result.ok(b);
    }

    /**
     * 同步【钉钉】[用户]到本地
     *
     * @param ids 作废
     * @return
     */
    @GetMapping("/sync/dingtalk/user/toLocal")
    public Result syncDingtalkUserToLocal(@RequestParam(value = "ids", required = false) String ids) {
        SyncInfoVo syncInfo = dingtalkService.syncThirdAppUserToLocal();
        if (syncInfo.getFailInfo().size() == 0) {
            return Result.OK("同步成功", syncInfo);
        } else {
            return Result.error("同步失败", syncInfo);
        }
    }

}
